
/**
* Pager object for record paging data
* @extends Kwik.Object
* @requires Kwik.Object
* @constructor
* @created 1:23 AM 8/10/2009
* @modified 1:23 AM 8/10/2009
*/
Kwik.Data.Pager = function(config)
{
	/** @ignore */
	Kwik.Utility.extend(this, "Kwik.Object");
	this.__class.push("Kwik.Data.Pager");

	/** Indication whether the pager is enabled @type Boolean */
	this.enabled = false;
	/** Current page of data @type Number */
	this.page = 1;
	/** Amount of available pages, should be set by the connector @type Number */
	this.pageCount = 1;
	/** Amount of records on a page @type Number */
	this.pageSize = 0;
	/** Amount of records available, should be set by the connector @type Number */
	this.recordCount = 0;
	
	/** Enable this pager object @type Kwik.Data.Pager */
	this.enable = function Pager_enable()
	{
		this.enabled = true;
		return this;
	};

	/** Disable this pager object @type Kwik.Data.Pager */
	this.disable = function Pager_disable()
	{
		this.enabled = false;
		return this;
	};

	/** Set the page size and updates the page count if the record count is set @type Kwik.Data.Pager */
	this.setPageSize = function Pager_setPageSize(size)
	{
		if(!Kwik.Type.isNumber(size)){throw new Error("Kwik.Data.Pager.setPageSize: Incorrect parameter specified, expected Number");}
		if(this.pageSize == size){return;}

		this.pageSize = size;
		if(this.recordCount>0)
		{
			this.pageCount = Math.ceil(this.recordCount/this.pageSize);
			if(this.page > this.pageCount){this.page = this.pageCount;}
		}
		return this;
	};

	/** Set the record count and updates the page count if the page size is set @type Kwik.Data.Pager */
	this.setRecordCount = function Pager_setRecordCount(count)
	{
		if(!Kwik.Type.isNumber(count)){throw new Error("Kwik.Data.Pager.setPageSize: Incorrect parameter specified, expected Number");}
		if(this.recordCount == count){return;}

		this.recordCount = count;
		if(this.pageSize > 0)
		{
			this.pageCount = Math.ceil(this.recordCount/this.pageSize);
			if(this.page > this.pageCount){this.page = this.pageCount;}
		}
	};

	/** Configure this pager object @type Kwik.Data.PagerConfig */
	this.configure = function Column_configure(config)
	{
		config = this.Kwik$Object.configure(config);

		if(config.enabled === true || config.enabled === false){this.enabled = config.enabled;}
		if(Kwik.Type.isNumber(config.page)){this.page = config.page;}
		if(Kwik.Type.isNumber(config.pageSize)){this.setPageSize(config.pageSize);}
		if(Kwik.Type.isNumber(config.recordCount)){this.setRecordCount(config.recordCount);}

		return config;
	};

	/** @ignore */
	this.main = function(config)
	{
		if(config){this.configure(config);}
	}; this.main(config);
};

/**
* Data pager configuration object
* @constructor
* @created 12:21 AM 7/29/2009
* @modified 12:21 AM 7/29/2009
*/
Kwik.Data.PagerConfig = function()
{
	/** Indication whether the pager is enabled @type Boolean */
	this.enabled = false;
	/** Current page of data @type Number */
	this.page = 1;
	/** Amount of records on a page @type Number */
	this.pageSize = 0;
	/** Amount of records available, should be set by the connector @type Number */
	this.recordCount = 0;
}